//
//  ShopProductAddCheckImageView.m
//  newShop
//
//  Created by scjh on 15/5/20.
//  Copyright (c) 2015年 wangliang0. All rights reserved.
//

#import "ShopProductAddCheckImageView.h"


@implementation ShopProductAddCheckImageView

- (instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        
        self.frame = frame;
        [self UI];
    }
    return self;
}

- (void) UI{
    
    self.backgroundColor = [UIColor whiteColor];
    
    UIButton *backButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 20, 100, 50)];
    [backButton setTitle:@"返回" forState:UIControlStateNormal];
    [backButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self addSubview:backButton];
    
    UIButton *deleteButton =
    [[UIButton alloc] initWithFrame:CGRectMake(CGRectGetWidth(self.frame) - 100, 20, 100, 50)];
    [deleteButton setTitle:@"删除" forState:UIControlStateNormal];
    [deleteButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [self addSubview:deleteButton];
    deleteButton.hidden = YES;
    
    CGFloat wide = CGRectGetWidth(self.frame);
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, wide, wide)];
    [self addSubview:imageView];
    imageView.center = self.center;
    self.photoImageView = imageView;
    
    UIButton *changeButton =
    [[UIButton alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(imageView.frame) + 20, 95, 37)];
    [changeButton setTitle:@"替换图片" forState:UIControlStateNormal];
    [changeButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    changeButton.center =
    CGPointMake(CGRectGetWidth(self.frame) / 2,changeButton.center.y);
    [self addSubview:changeButton];
    changeButton.layer.cornerRadius = 5;
    changeButton.layer.borderColor = [UIColor blackColor].CGColor;
    changeButton.layer.borderWidth = 2;
    
    backButton.tag = 1;
    deleteButton.tag = 2;
    changeButton.tag = 3;
    [backButton addTarget:self
                   action:@selector(buttonAction:)
         forControlEvents:UIControlEventTouchUpInside];
    [deleteButton addTarget:self
                   action:@selector(buttonAction:)
         forControlEvents:UIControlEventTouchUpInside];
    [changeButton addTarget:self
                   action:@selector(buttonAction:)
         forControlEvents:UIControlEventTouchUpInside];
    
}

- (void)buttonAction:(UIButton *)sender {
    
    if ([self.delegate respondsToSelector:@selector(protocolDelegte:withInfo:)]) {
        
        [self.delegate protocolDelegte:self withInfo:@{@"index":@(sender.tag)}];
    }
}

@end
